package com.xiaoyu.awakening.ai.evaluation.server;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.xiaoyu.awakening.ai.evaluation.dto.CreateSingleEvalTaskDTO;
import com.xiaoyu.awakening.ai.evaluation.dto.EvalCallbackDTO;
import com.xiaoyu.awakening.ai.evaluation.dto.EvalTaskQueryDTO;
import com.xiaoyu.awakening.ai.evaluation.entity.AwkEvalEntity;
import com.xiaoyu.awakening.ai.evaluation.service.IAwkEvalService;
import com.xiaoyu.awakening.common.core.dto.Result;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ForgeEvalController
 *
 * @author wangxiaoyu
 * @date 2025/8/20 15:13
 * @since v1.0
 */
@Tag(name = "RAG评估模块")
@RestController
@RequestMapping("/eval")
@Log4j2
public class AwkEvalController {
    @Resource
    private IAwkEvalService forgeEvalService;

    @PostMapping("/createSingleEvalTask")
    public Result<AwkEvalEntity> eval(@RequestHeader("Token") String token, @RequestBody CreateSingleEvalTaskDTO createSingleEvalTaskDTO) {
        if (StrUtil.isBlank(createSingleEvalTaskDTO.getToken())) {
            createSingleEvalTaskDTO.setToken(token);
        }
        log.info("createSingleEvalTask, createSingleEvalTaskDTO: {}", JSON.toJSONString(createSingleEvalTaskDTO));
        AwkEvalEntity evalTaskDTO = forgeEvalService.createSingleEvalTask(createSingleEvalTaskDTO);
        return Result.success(evalTaskDTO);
    }

    @PostMapping("/list")
    public Result<List<AwkEvalEntity>> list(@RequestBody EvalTaskQueryDTO evalTaskQueryDTO) {
        List<AwkEvalEntity> evalTaskDTOList = forgeEvalService.queryList(evalTaskQueryDTO);
        return Result.success(evalTaskDTOList);
    }

    @PostMapping("/callback")
    public Result<Boolean> callback(@RequestBody EvalCallbackDTO evalCallbackDTO) {
        log.info("callback, evalCallbackDTO: {}", JSON.toJSONString(evalCallbackDTO));
        forgeEvalService.callback(evalCallbackDTO);
        return Result.success();
    }
}
